﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="WpfExtensions.cs" company="GT">
//   Gunther Taborga
// </copyright>
// <summary>
//   Defines the WpfExtensions type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace BatchID3.Editor.Extensions
{
    using System;
    using System.Windows;
    using System.Windows.Forms;
    using System.Windows.Media;

    public static class WpfExtensions
    {
        public static IWin32Window GetIWin32Window(this Visual visual)
        {
            var source = PresentationSource.FromVisual(visual) as System.Windows.Interop.HwndSource;
            IWin32Window win = new OldWindow(source.Handle);

            return win;
        }

        private class OldWindow : IWin32Window
        {
            private readonly IntPtr handle;

            public OldWindow(IntPtr handle)
            {
                this.handle = handle;
            }

            IntPtr IWin32Window.Handle
            {
                get { return this.handle; }
            }
        }
    }
}
